local jizhan = fk.CreateSkill {
  name = "jizhan",
}

jizhan:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local get = room:getNCards(1)
    room:moveCardTo(get, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player)
    while true do
      room:delay(500)
      local num1 = Fk:getCardById(get[#get]).number
      local choice = room:askToChoice(player,
        { choices = { "jizhan_more", "jizhan_less" }, skill_name = self.name, prompt = "#jizhan-choice:::" ..
        tostring(num1) })
      local id = room:getNCards(1)[1]
      local num2 = Fk:getCardById(id).number
      room:moveCardTo(id, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player)
      table.insert(get, id)
      if (choice == "jizhan_more" and num1 >= num2) or (choice == "jizhan_less" and num1 <= num2) then
        room:setCardEmotion(id, "judgebad")
        room:delay(600)
        break
      else
        room:setCardEmotion(id, "judgegood")
        room:delay(600)
      end
    end
    room:moveCardTo(get, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player)
    return true
  end,
})

return jizhan
